// Do file that collects info on the number of children at time of immigration
//
// Last changed: 2020-06-04 (KOL)
  
  use "E:\ProjData\UtplaceringsData8594\utp-UtpData.dta", clear
  capture drop occ
  bysort LopNr: gen occ = _n
  keep if occ == 1
  keep LopNr InvAr
  tempfile InvUrval 
  save `InvUrval'
  
  use "D:\SCB_ConPol\Stata\RTB\Fodelseuppg", clear
  bysort LopNr: egen cID = count(LopNr)
  drop if cID >1 
  
  tempfile FodUppg
  save `FodUppg'
  
  use "D:\SCB_ConPol\Stata\FlerGen\Barn.dta", clear
  rename LopNr LopNr_Foralder
  rename LopNrBarn LopNr
  drop if LopNr == .
  
  merge m:1 LopNr using `FodUppg', keepusing(FodArMan)
  keep if _merge == 3
  drop _merge  
  
  rename LopNr LopNrBarn
  rename LopNr_For LopNr
  
  merge m:1 LopNr using `InvUrval'
  keep if _merge == 3
  drop _merge 
  
  gen FodArBarn = floor(FodArMan/100)
  gen rBarn = InvAr-FodArBarn
  gen D0_15 = inrange(rBarn, 0, 15)
  
  bysort LopNr: egen Barn0_15_InvAr = total(D0_15)
  bysort LopNr: gen occ = _n

  keep if occ == 1
  
  save "E:\ProjData\UtplaceringsData8594\utp-BarnInvAr", replace
